/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author wei
 */
@Entity(name="ShippingRequest")
public class ShippingRequestEntity extends DataObjectEntity implements Serializable {
    @ManyToOne
    private AddressEntity address;
    @ManyToOne
    private ProductEntity product;
    private long quantity;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date shippingDate;
    
    @ManyToOne
    private PurchaseOrderEntity purchaseOrder;
    
    @ManyToOne
    private PackingOrderEntity packingOrder;

    public ShippingRequestEntity() {
        super();
    }

    public AddressEntity getAddress() {
        return address;
    }

    public void setAddress(AddressEntity address) {
        this.address = address;
    }

    public ProductEntity getProduct() {
        return product;
    }

    public void setProduct(ProductEntity product) {
        this.product = product;
    }

    public long getQuantity() {
        return quantity;
    }

    public void setQuantity(long quantity) {
        this.quantity = quantity;
    }

    public PurchaseOrderEntity getPurchaseOrder() {
        return purchaseOrder;
    }

    public void setPurchaseOrder(PurchaseOrderEntity purchaseOrder) {
        this.purchaseOrder = purchaseOrder;
    }

    public PackingOrderEntity getPackingOrder() {
        return packingOrder;
    }

    public void setPackingOrder(PackingOrderEntity packingOrder) {
        this.packingOrder = packingOrder;
    }
    
    public double getTotalPrice(){
        Double unitPrice = purchaseOrder.getProductToUnitPriceHash().get(product);
        if(unitPrice==null)
            unitPrice=0.0;
        return unitPrice*quantity;
    }
    
    public ProductQuantityPriceEntity getPQP(){
        ProductQuantityPriceEntity pqp = new ProductQuantityPriceEntity();
        pqp.setProduct(product);
        pqp.setQuantity(quantity);
        pqp.setPrice(getTotalPrice());
        return pqp;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ShippingRequestEntity other = (ShippingRequestEntity) obj;
        if (this.address != other.address && (this.address == null || !this.address.equals(other.address))) {
            return false;
        }
        if (this.product != other.product && (this.product == null || !this.product.equals(other.product))) {
            return false;
        }
        if (this.quantity != other.quantity) {
            return false;
        }
        if (this.purchaseOrder != other.purchaseOrder && (this.purchaseOrder == null || !this.purchaseOrder.equals(other.purchaseOrder))) {
            return false;
        }
        if (this.packingOrder != other.packingOrder && (this.packingOrder == null || !this.packingOrder.equals(other.packingOrder))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 73 * hash + (this.address != null ? this.address.hashCode() : 0);
        hash = 73 * hash + (this.product != null ? this.product.hashCode() : 0);
        hash = 73 * hash + (int) (this.quantity ^ (this.quantity >>> 32));
        hash = 73 * hash + (this.purchaseOrder != null ? this.purchaseOrder.hashCode() : 0);
        hash = 73 * hash + (this.packingOrder != null ? this.packingOrder.hashCode() : 0);
        return hash;
    }
    

    @Override
    public String childToString() {
        return "ShippingRequestEntity{" + "address=" + address + ", product=" + product + ", quantity=" + quantity + ", purchaseOrder=" + purchaseOrder + ", packingOrder=" + packingOrder + '}';
    }

    public Date getShippingDate() {
        return shippingDate;
    }

    public void setShippingDate(Date shippingDate) {
        this.shippingDate = shippingDate;
    }
    
}
